from django.contrib import admin
from models import Page
from forms import PageAdminForm
from reversion.admin import VersionAdmin
from reversion.revisions import revision

class PageAdmin(VersionAdmin):
    list_display = ('path', 'parent', 'url', 'revision_count', 'template_name', 'order', 'order_link', 'page_link')
    list_filter = ('parent',)
    fieldsets = (
        (None, {
            'fields': ('title', 'parent', 'page_url', 'content')
        }),
        ('Opzioni avanzate', {
            'classes': ('collapse',),
            'fields': ('is_public', 'template_name')
        }),
        ('Revisione', {
            'fields': ('comment',),
        }),
    )
    form = PageAdminForm
    ordering = ('parent', 'order')
    
    def save(self, request, obj, form, change):
        obj.revision_comment = form.cleaned_data['comment']
        obj.save()
        
    class Media:
        js = ('scripts/jquery.js', 'scripts/jquery.ui.js', 'scripts/fckeditor/fckeditor.js', 'scripts/fckeditor_config/loader.js')

admin.site.register(Page, PageAdmin)
